
package de.uni.wuppertal.server.http;

import java.net.URI;

/**
 * @author Martin Schröder
 * @author Patrik Nordsiek
 */
public class HTTPRequest extends HTTPHeaders
{
	public static final long serialVersionUID = 1;
	
	private HTTPServer server;
	private String method;
	private URI uri;
	private String resource;
	private String protocol;
	private String body;
	
	public HTTPRequest(HTTPServer server)
	{
		this.server = server;
	}
	
	public String getMethod()
	{
		return method;
	}
	
	public void setMethod(String m)
	{
		String mt = m.toUpperCase();
		String[] methods = server.getSupportedMethods();
		boolean found = false;
		
		for(int length = methods.length, i = 0; i < length; i++)
		{
			if(methods[i].equals(mt))
			{
				found = true;
				
				break;
			}
		}
		
		if(!found)
		{
			throw new HTTPServerException("Unsupported Request Method: " + method);
		}
		
		method = mt;
	}
	
	public URI getURI()
	{
		return uri;
	}
	
	public void setURI(URI uri)
	{
		this.uri = uri;
		
		resource = uri.getPath();
	}
	
	public String getResource()
	{
		return resource;
	}
	
	public String getProtocol()
	{
		return protocol;
	}
	
	public void setProtocol(String protocol)
	{
		this.protocol = protocol;
	}
	
	public String getBody()
	{
		return body;
	}
	
	public void setBody(String body)
	{
		this.body = body;
	}
}
